#include <iostream>
using namespace std;

class Obj2; 
class Obj1;

class Obj1{
    friend std::ostream& operator<<(std::ostream& out, const Obj1& obj);
    friend Obj2;

    private:
        int x;
    protected:
        int y;
    public:
        int z;
    public:
        Obj1():x(1),y(1),z(1){}
        void show(const Obj2& obj);
};

class Obj2{
    private:
        int x;
    protected:
        int y;
    public:
        int z;
    public:
        Obj2():x(1),y(1),z(1){}
        void show(const Obj1& obj);
};

void Obj2::show(const Obj1& obj){
    cout << obj.x << "," << obj.y << "," << obj.z << endl;
}

void Obj1::show(const Obj2& obj){
    cout << obj.x << "," << obj.y << "," << obj.z << endl;
}

std::ostream& operator<<(std::ostream& out, const Obj1& obj)
{
    out << obj.x << "," << obj.y << "," << obj.z;
    return out;
}


void TESTfriend(){
    Obj1 a;
    Obj2 b;
    cout << a << endl;
    b.show(a); // b是a的友元类，因此可以访问a
    //a.show(b); // 友元是单向关系，a不是b的友元类，因此访问不了b的私有成员
}

int main(){
    TESTfriend();
    return 0;
}
